#ifndef CHATTABLEMODEL_H
#define CHATTABLEMODEL_H

#include <QAbstractTableModel>
#include <QStyledItemDelegate>
#include <QSharedPointer>
#include "messageitem.h"
class QRect;
class QPainterPath;
class QTextDocument;

class ChatItemDelegate: public QStyledItemDelegate
{
    Q_OBJECT
public:
    ChatItemDelegate(QObject * parent = 0);
    virtual ~ChatItemDelegate();

    void setContactProfileImage(QPixmap const& image)
    {
        contactProfileImage = &image;
    }

    virtual void	paint ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const;
    virtual QSize sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const ;

protected:
    void drawRect(QPainter * const painter, QRect const& rect, bool const isSelected, bool const isActivated, bool const leftArrow) const;
    void bezierPathWithRect(QRect const& rect, QPainterPath& bp, bool leftArrow) const;
    void MakeHtmlString(const QModelIndex & index, QString& html) const;


private:
    QSharedPointer<QTextDocument> document;
    const QPixmap* contactProfileImage;

};

class ChatTableModel : public QAbstractTableModel
{
    Q_OBJECT
public:
    explicit ChatTableModel(MessageList& list, QObject *parent = 0);

    int rowCount(const QModelIndex &parent) const;
    int columnCount(const QModelIndex &parent) const;
    QVariant data(const QModelIndex &index, int role) const;
    void addMessage(MessageItem& item);
signals:

public slots:

private:
    MessageList& messageList;
};

#endif // CHATTABLEMODEL_H
